<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
<#--此ftl中用到的css-->
<link rel="stylesheet" href="/assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css">

</#assign>
<#assign js>
<script src="/assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="/assets/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" charset="UTF-8"></script>


<#--此ftl中用到的js-->
<script>
	$(".btn-submit").click(function () {
		// 校验表单合法
		var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
		bootstrapValidator.validate();
		if(bootstrapValidator.isValid()){
			$.ajax({
				type: "POST",
				url: "/userCoupon/send",
				data: $(".form-edit").serialize(),
				dataType: "JSON",
				success: function(res){
					layer.msg(res.message, {time: 2000
					}, function(){
						location.href="/userCoupon/index";
					});
				}
			});
		}else{
			return false;
		}
	});


	$('.form-edit').bootstrapValidator({
		message: '请输入有效值',
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		}
	});

    /*$("#couponId").change(function (e){
        debugger;
        var start = e.currentTarget.start;
		//alert(start);

    });*/

    $("#sendType").change(function (e){
        var sendType = e.currentTarget.value;
		if (sendType=='1'){
		    $("#userIds").attr('disabled',true);
		}else {

            $("#userIds").attr('disabled',false);
		}

    });

    $('#startTime,#endTime').datepicker({
        autoclose: true,
        format:"yyyy-mm-dd",
        todayHighlight:true,
        language:"zh-CN"
    });

    $('#startTime').unbind("change");
    $('#startTime').change(function(){
        $('#endTime').datepicker('setStartDate', $("#startTime").val());
    });
    $('#endTime').unbind("change");
    $('#endTime').change(function(){
        $('#startTime').datepicker('setEndDate', $("#endTime").val());
    });


</script>
</#assign>
<@layout title="优惠券发放" active="userCoupon">
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<#if isAdd>
            发放
        <#else>
            编辑
        </#if>
		<small>优惠券详细信息</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
		<li><a href="#"><i class="fa fa-list-ul"></i> 优惠券管理</a></li>
		<li class="active"><i class="fa fa-edit"></i>优惠券发放</li>
	</ol>
</section>
<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Default box -->
			<div class="box  box-primary">
				<form class="form-horizontal form-edit" method="post" action="userCoupon/send">
					<div class="box-body">
						<input type="hidden" id="id" name="id" value="${userCoupon.id!}">
						<input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">发放方式：</label>
                            <div class="col-sm-10">
                                <select id="sendType" name="sendType" required class="form-control">
                                    <option value="">请选择</option>
                                    <option value="1">所有用户</option>
                                    <option value="2">特定用户</option>
                                </select>
                            </div>
                        </div>

						<div class="form-group">
							<label class="col-sm-2 control-label">用户手机号：</label>
							<div class="col-sm-10">
								<textarea required placeholder="请输入用户手机号，多个用户手机号使用';'隔开" id="userIds" name="userIds" class="form-control" type="text" value="${userCoupon.userId!}" ></textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">优惠券：</label>
							<div class="col-sm-10">
								<select id="couponId" name="couponId" required class="form-control">
									<option value="">请选择发放的优惠券</option>
									<#list coupons as coupon>
										<option value="${coupon.id}" data-start="${coupon.id}">${coupon.name+'(优惠金额'+coupon.amount+')'}</option>
									</#list>
								</select>
							</div>
						</div>


						<div class="form-group">
							<label class="col-sm-2 control-label">优惠券有效日期：</label>
							<div class="col-sm-5">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input placeholder="请输入开始日期" id="startTime" name="startTime" class="form-control" type="text" value="${(userCoupon.startTime?string('yyyy-MM-dd'))!}" >
                                </div>
							</div>
                            <div class="col-sm-5">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input placeholder="请输入到期日期" id="endTime" name="endTime" class="form-control" type="text" value="${(userCoupon.endTime?string('yyyy-MM-dd'))!}" >
                                </div>
                            </div>
						</div>


					<div class="box-footer">
						<button type="button" class="btn btn-default btn-back">返回</button>
						<button type="button" class="btn btn-info pull-right btn-submit">发放</button>
					</div>

				</form>
			</div>
			<!-- /.box -->
		</div>
	</div>
</section>
<!-- /.content -->
</@layout>
